// components/diy/pictures/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    diyPramas:{
      type:Object
    },
    diyStyle:{
      type:Object
    },
    diyData:{
      type:Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    swiperCurrent: 0,
    slider:[],
    swiperBtnHeight:0, //图组高度
    lineSize:0, //行数
    pageSize:0  //页数
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //轮播图的切换事件
    swiperChange: function(e){
      //只要把切换后当前的index传给<swiper>组件的current属性即可
      this.setData({
        swiperCurrent: e.detail.current
      })
    },

    //点击指示点切换
    chuangEvent: function(e){
      this.setData({
        swiperCurrent: e.currentTarget.id
      })
    }
  },

  ready: function(){
    var num = this.data.diyData.length; //总共图片数
    var rownum = this.properties.diyPramas.rownum; //每行显示个数
    var pageSize =0;//总共页数
    if(num%rownum == 0){
      pageSize = parseInt(num/rownum)
    }else{
      pageSize = parseInt(num/rownum) + 1
    }

    this.setData({
        pageSize:pageSize,
    }) 
    var that = this
    var  showtype = this.properties.diyPramas.showtype
    if(showtype == '1'){
      var query = wx.createSelectorQuery().in(this)
      query.select('.picturesAll').boundingClientRect((rect) => {
        var width = rect.width;
        var paddingleft = that.properties.diyStyle.paddingleft
        var paddingtop = that.properties.diyStyle.paddingtop
        var imageHeight = (width - paddingleft*2*rownum  - 2*paddingleft )/rownum
        var height = imageHeight + paddingtop * 2  + 20
        this.setData({
          swiperBtnHeight: height
        })
      }).exec()
    }
    
  }
})
